<template>
  <div class="address-manager-cell">
    <div class="address-manager-cell__contain"
         @click="clickItem">
      <div class="address-manager-cell__right"
           ref="cell">
        <div class="address-manager-cell__right__auth">
          <div class="address-manager-cell__right__auth__name">{{data.recipients}}
            <span v-if="data.flag === '0'">(默认地址)</span>
          </div>
          <div class="address-manager-cell__right__auth__phone">{{data.cellphone}}</div>
        </div>
        <div class="address-manager-cell__right__address"
             :style="{color:'#666666'}">
          <div class="address-manager-cell__right__address__left">收货地址: </div>
          <div class="address-manager-cell__right__address__right">
            {{data.province}}{{data.city}}{{data.area}}{{data.adress}}
          </div>

        </div>

        <div class="address-manager-cell__right__diving"></div>
      </div>
      <div class="address-manager-cell__check"
           :style="{height:cellHeight}">
        <div class="uncheck"
             :class="{check: selectedIndex === index}"></div>
      </div>
    </div>
  </div>
</template>
<style lang="stylus" scoped>
.address-manager-cell {
  .address-manager-cell__contain {
    width: 100%;
    background: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    box-sizing: border-box;
    padding-bottom: 0;
  }

  .address-manager-cell__check {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
    justify-content: center;
    align-items: center;
    margin-left: 20px;

    .uncheck {
      background-image: url('~@image/icon-unchecked.png');
      background-size: 30px 30px;
      width: 30px;
      height: 30px;
    }

    .check {
      background-image: url('~@image/icon-checked.png');
      background-size: 30px 30px;
      width: 30px;
      height: 30px;
    }
  }

  .address-manager-cell__right {
    margin-left: 10px;

    .address-manager-cell__right__auth {
      margin-bottom: 20px;
      width: 629px;
      display: flex;
      flex-direction: row;
      justify-content: space-between;

      .address-manager-cell__right__auth__name {
        font-size: 28px;
        width: 309px;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        overflow: hidden;

        span {
          margin-left: 9px;
          color: #e31436;
          font-size: 24px;
        }
      }

      .address-manager-cell__right__auth__phone {
        font-size: 28px;
      }
    }

    .address-manager-cell__right__address {
      font-size: 26px;
      margin-bottom: 20px;
      display: flex;
      align-items: flex-start;

      .address-manager-cell__right__address__left {
        width: 120px;
      }

      .address-manager-cell__right__address__right {
        // margin-left: 2px;
        width: 501px;
      }
    }

    .address-manager-cell__right__diving {
      width: 100%;
      height: 1px;
      background: #dddddd;
    }
  }
}
</style>

<script>
export default {
  name: 'address-manager-cell',
  data () {
    return {
      cellHeight: 0
    }
  },
  props: {
    selectedIndex: Number, // 当前选中的“默认地址”的条目下标
    index: Number, // 当前条目的下标
    data: Object,
    area: String
  },
  mounted () {
    this.$nextTick(() => {
      let rect = this.$refs.cell.getBoundingClientRect()
      this.cellHeight = (rect.bottom - rect.top) + 'px'
    })
  },
  methods: {
    getSelectedImage: function () {
      if (this.selectedIndex === this.index) {
        return require(`@image/icon-checked.png`)
      } else {
        return require(`@image/icon-unchecked.png`)
      }
    },
    // 选中 以及 未选中 “默认地址” 按钮 的图片切换
    getCheckedImage: function () {
      if (this.data && this.data.flag === '0') {
        return require(`@image/icon-checked.png`)
      } else {
        return require(`@image/icon-unchecked.png`)
      }
    },
    // 点击了 “默认地址”
    setCheckedImage: function () {
      // 如果选中的 和当前索引相同 不作处理
      if (this.data.flag !== '0') {
        this.$emit('switchDefaultSelected', this.index)
      }
    },
    clickItem: function () {
      this.$emit('switchOrderSelected', this.index)
    }
  }
}
</script>
